package com.jy.wms.web;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.SetAndModifyModel;
import com.jy.wms.pojo.WmsLibraryPosition;
import com.jy.wms.service.SysMenuService;
import com.jy.wms.service.WmsLibraryPositionService;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/kuwei")
public class WmsKwRouter extends BaseController<WmsLibraryPositionService,WmsLibraryPosition> {
    @Autowired
    SysMenuService menuService;
    //库位页面
    @RequestMapping(value = "/kuwei/{menu}")
    public  String  toKuwei(@PathVariable("menu") String menu, Model model){
        model.addAttribute("functions",menuService.getFunctions(menu));
        return "base/wmsKw/kuwei";
    }
    //添加库位
    @RequestMapping(value = "/addkuwei")
    public  String addkuwei(){
        return "base/wmsKw/addkuwei";
    }
    //导出
    @RequestMapping(value = "/exportDetail")
    public  String exportDetail(){
        return "base/wmsKw/exportDetail";
    }
    //库位详情
    @RequestMapping(value = "/getkuwei")
    public String toEditkuwei(String id,Model model){
        model.addAttribute("id",id);
        return "base/wmsKw/kuweimingxi";
    }
    /*跳转到修改库位页面*/
    @RequestMapping(value = "/editkuwei")
    public String editkuwei(String id, Model model) {
        model.addAttribute("id",id);
        return "base/wmsKw/editkuwei";
    }

    @ApiOperation(value = "查询库位信息", response = JSONObject.class, notes = "查询库位信息")
    @PostMapping(value = "/getFind")
    public @ResponseBody
    JSONObject getFind( @RequestBody SetAndModifyModel setModel,HttpSession session) {
        WmsLibraryPosition wmsLibraryPosition =new WmsLibraryPosition();
        JSONObject jb=new JSONObject();
        try {
            UserInfo userinfo= (UserInfo) session.getAttribute(SessionInfo.USER_INFO);
            String ckid=String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库编号
            wmsLibraryPosition = baseService.baseSelectByPrimaryKey(setModel.getId(),ckid);
            JSONObject jsonObject3 = new JSONObject();
            jsonObject3.accumulate("id",wmsLibraryPosition.getSskqid());
            jsonObject3.accumulate("text",wmsLibraryPosition.getKqmc());
            String str= com.alibaba.fastjson.JSONObject.toJSONString(wmsLibraryPosition);
            jb=JSONObject.fromObject(str);
            jb.accumulate("selectId",jsonObject3);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return jb;
    }
}
